package zz.app.jmhviewer;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import zz.app.jmhviewer.JMH.JMHJsonData;

public class MainActivity extends AppCompatActivity {

    ListView musicListView;
    MusicListAdapter musicListAdapter;
    static final String host="123.56.28.160";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);
        musicListView=findViewById(R.id.musicListView);
        musicListAdapter=new MusicListAdapter(this);
        musicListView.setAdapter(musicListAdapter);
        GetJsonDataTask task=new GetJsonDataTask(this,musicListAdapter);
        task.setOnFinishedResultListener(new OnFinishedResultListener() {
            @Override
            public void onFinishedResult(boolean ok) {
                if(!ok){
                    Toast.makeText(MainActivity.this,"请检查网络连接!",Toast.LENGTH_LONG).show();
                }
            }
        });
        task.execute(host);
        musicListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                JMHJsonData data=(JMHJsonData)musicListAdapter.getItem(position);
                Intent intent=new Intent(MainActivity.this,ShowActivity.class);
                intent.putExtra("jsonData",data);
                intent.putExtra("host",host);
                startActivity(intent);

            }
        });
    }
}
